// 生成代码, 修改去MotionBDTemplate.txt模板修改
export class AnimationSheet{ guid:string; count:number; }
export class SoundSheet{ guid:string; volume:number; }
export class DisplacementSheet { displacement:number[] }

export enum EnumSpawnAroundBuffSheet{
    ball,
    player,
}

export enum EnumEmitTrajectoryType{
    normal = 'normal',
    bezier = 'bezier',
}

export class AreaSheet{
    constructor(
        public transform:number[],
        public effectID?:string,
        public effectScale?:number[],
        public effectColor?:string,
        public soundID?:string,
        public damageFactor?:number,
        public control?:number,
        public repel?:number,
        public levitate?:number,
        public debuff?:number,
        private attrType?:string,
        private attrValue?:string,
    ) { 
    }
}

export class SpawnAroundBuffSheet{
    constructor(
        public effectType:EnumSpawnAroundBuffSheet,
        public buffID:number,
        public range:number,
    ) { }
}

export class EffectSheet{
    guid:string; socketType:number; offset:Vector; rotation:Rotation; scale:Vector; color:LinearColor; projection:boolean
    constructor(guid:string,socketType:number,transform:number[],color:string,projection:number) {
        this.guid = guid
        this.socketType = socketType
        this.offset = new Vector(transform[0],transform[1],transform[2])
        this.rotation = new Rotation(transform[3],transform[4],transform[5])
        this.scale = new Vector(transform[6],transform[7],transform[8])
        if(color){
            this.color = LinearColor.colorHexToLinearColor(color)
        }
        if(projection == 1){
            this.projection = true
        }else{
            this.projection = false
        }
    }
}

export class CameraTranslate {
    position:Readonly<Vector>
    rotation:Readonly<Rotation>
    constructor(pos:number[],rot:number[]) {
        this.position = new Vector(pos[0],pos[1],pos[2])
        this.rotation = new Rotation(rot[0],rot[1],rot[2])
    }
}

export class CameraEaseTranslate {
    position:Readonly<Vector>
    rotation:Readonly<Rotation>
    constructor(pos:number[],rot:number[],public duration:number) {
        this.position = new Vector(pos[0],pos[1],pos[2])
        this.rotation = new Rotation(rot[0],rot[1],rot[2])
    }
}

export class SlotChange {
    slot:number
    constructor(slot:number) {
        this.slot = slot
    }
}

export class EmitSheet {
    translate:Readonly<Vector>
    rotationOffset:Readonly<Vector>
    scale:Readonly<Vector>
    areaScale:Readonly<Vector>
    hitEffectScale:Readonly<Vector>
    positionOffset:Readonly<Vector>
    damageFactor:number
    repel?:number
    control?:number
    levitate?:number
    debuff?:number
    hitDisable?:boolean
    hitInterval?:number
    gravity?:number

    lockDistance?:number
    trajectoryType?:string
    trajectoryArgs?:string

    color:LinearColor

    constructor(
      public effectID:string,
      public duration:number,
      translate:number[],
      positionOffset:number[],
      public hitEffect?:string,
      rotationOffset?:number[],
      scale?:number[],
      areaScale?:number[],
      hitEffectScale?:number[],
      damageFactor?:number,
      hitDisable?:number,
      hitInterval?:number,
      gravity?:number,
      lockDistance?:number,
      trajectoryType?:string,
      trajectoryArgs?:string,
      private attrType?:string,
      private attrValue?:string,
      color?:string
    ) {
        this.translate = new Vector(translate[0],translate[1],translate[2])
        this.rotationOffset = rotationOffset?new Vector(
            rotationOffset[0],
            rotationOffset[1],
            rotationOffset[2],
        ):Vector.zero
        this.scale = scale?new Vector(
            scale[0],
            scale[1],
            scale[2],
        ):Vector.one
        this.areaScale = areaScale?new Vector(
            areaScale[0],
            areaScale[1],
            areaScale[2],
        ):Vector.one
        this.hitEffectScale = hitEffectScale?new Vector(
            hitEffectScale[0],
            hitEffectScale[1],
            hitEffectScale[2],
        ):Vector.one
        this.positionOffset = positionOffset?new Vector(
            positionOffset[0],
            positionOffset[1],
            positionOffset[2],
        ):Vector.zero

        this.effectID = effectID
        this.duration = duration
        this.hitEffect = hitEffect
        this.damageFactor = damageFactor??1
        this.hitDisable = hitDisable != null
        this.hitInterval = hitInterval
        this.gravity = gravity
        
        this.lockDistance = lockDistance
        this.trajectoryType = trajectoryType || EnumEmitTrajectoryType.normal
        this.trajectoryArgs = trajectoryArgs

        if(color){
            this.color = LinearColor.colorHexToLinearColor(color)
        }
        
    }
}

export class MotionSheets {
    animation?:AnimationSheet;
    area?:AreaSheet;
    effect?:EffectSheet;
    sound?:SoundSheet;
    emit?:EmitSheet
    displacement?:number[];
    levitate?:number;
    flashRange?:number;
    breakingPoint?:boolean;
    cameraTranslate?:CameraTranslate;
    cameraEaseTranslate?:CameraEaseTranslate;
    invisibleDuring?:number;
    spawnBuffID?:number;
    spawnAroundBuff?:SpawnAroundBuffSheet;
    countDuring?:number;
    countExtraForce?:number;
    countExtraEffect?:string;
    slotChange?:SlotChange;

    constructor(
        // 动画
        animID?:string,
        count?:number,
        // 特效
        effectID?:string,
        effectSocket?:number,
        effectTransform?:number[],
        effectColor?:string,
        projectionEffect?:number,
        // 判定
        obbTransform?:number[],
        obbEffectID?:string,
        obbEffectScale?:number[],
        obbEffectColor?:string,
        obbSoundID?:string,
        obbDamageFactor?:number,
        control?:number,
        repel?:number,
        obbLevitate?:number,
        debuff?:number,
        attrType?:string,
        attrValue?:string,
        // 音效
        soundID?:string,
        soundVolume?:number,
        // 位移
        displacement?:number[],
        // 脱手
        emitEffectID?:string,
        emitDuration?:number,
        emitTranslate?:number[],
        emitPositionOffset?:number[],
        emitRotationOffset?:number[],
        emitScale?:number[],
        emitAreaScale?:number[],
        emitHitEffect?:string,
        emitHitEffectScale?:number[],
        damageFactor?:number,
        hitDisable?:number,
        hitInterval?:number,
        gravity?:number,
        emitLockDistance?:number,
        emitTrajectoryType?:string,
        emitTrajectoryArgs?:string,
        emitAdditionAttrType?:string,
        emitAdditionAttrValue?:string,
        color?:string,
        // 浮空持续
        levitate?:number,
        // 瞬闪判定范围
        flashRange?:number,
        // 可中断标记
        breakingPoint?:number,
        // 摄像机位移
        cameraTranslatePos?:number[],
        cameraTranslateRot?:number[],
        // 摄像机缓动
        cameraEaseTranslatePos?:number[],
        cameraEaseTranslateRot?:number[],
        cameraEaseTranslateDuring?:number,
        // 隐身持续
        invisibleDuring?:number,
        // 产生buff
        spawnBuffID?:number,
        // 向附近派发buff
        spawnAroundBuffType?:number,
        spawnAroundBuffID?:number,
        spawnAroundBuffRange?:number,
        // 反击持续帧数
        countDuring?:number,
        // 反击附加速度
        countExtraForce?:number,
        // 槽位变换(目标槽位)
        slotChangeSlot?:number,
        // 反击附加特效参数
        countExtraEffect?:string,
    )
    {
        if(animID && count){
            let asd = new AnimationSheet()
            asd.guid = animID
            asd.count = count
            this.animation = asd
        }
        if(effectID && effectTransform && effectTransform.length == 9){
            this.effect = new EffectSheet(effectID, effectSocket, effectTransform,effectColor,projectionEffect)
        }
        if(obbTransform && obbTransform.length == 9){
            this.area = new AreaSheet(
                obbTransform,
                obbEffectID,
                obbEffectScale,
                obbEffectColor,
                obbSoundID,
                obbDamageFactor,
                control,
                repel,
                obbLevitate,
                debuff,
                attrType,
                attrValue,
            )
        }
        if(soundID && soundVolume){
            let ssd = new SoundSheet()
            ssd.guid = soundID
            ssd.volume = soundVolume
            this.sound = ssd
        }
        if(displacement && displacement.length == 3){
            this.displacement = displacement
        }
        if(emitEffectID && emitDuration && emitTranslate && emitTranslate.length == 3){
            this.emit = new EmitSheet(
                emitEffectID,
                emitDuration,
                emitTranslate,
                emitPositionOffset,
                emitHitEffect,
                emitRotationOffset,
                emitScale,
                emitAreaScale,
                emitHitEffectScale,
                damageFactor,
                hitDisable,
                hitInterval,
                gravity,
                emitLockDistance,
                emitTrajectoryType,
                emitTrajectoryArgs,
                emitAdditionAttrType,
                emitAdditionAttrValue,
                color,
            )
        }
        if(levitate) this.levitate = levitate
        if(flashRange) this.flashRange = flashRange
        if(breakingPoint) this.breakingPoint = true
        if(cameraTranslatePos && cameraTranslateRot){
            this.cameraTranslate = new CameraTranslate(cameraTranslatePos,cameraTranslateRot)
        }
        if(cameraEaseTranslatePos && cameraEaseTranslateRot && cameraEaseTranslateDuring){
            this.cameraEaseTranslate = new CameraEaseTranslate(cameraEaseTranslatePos,cameraEaseTranslateRot,cameraEaseTranslateDuring)
        }
        if(invisibleDuring){
            this.invisibleDuring = invisibleDuring
        }
        if(spawnBuffID){
            this.spawnBuffID = spawnBuffID
        }
        if (spawnAroundBuffType != undefined && spawnAroundBuffID != undefined && spawnAroundBuffRange != undefined) {
            this.spawnAroundBuff = new SpawnAroundBuffSheet(spawnAroundBuffType,spawnAroundBuffID,spawnAroundBuffRange)
        }
        if(countDuring){
            this.countDuring = countDuring
        }
        if(countExtraForce){
            this.countExtraForce = countExtraForce
        }
        if(countExtraEffect){
            this.countExtraEffect = countExtraEffect
        }
        if(slotChangeSlot){
            this.slotChange = new SlotChange(slotChangeSlot)
        }
    }
}

type MotionKeyValuePair = {[frame:number]:MotionSheets}
export class Motion{
    attackStraightDistance:number = 1e5
    isAttackMotion = false
    constructor(public name:MotionID,public count:number,public areaEffectOnce:boolean,public moveSpeed:number, public canNotMove:number,public sheets:MotionKeyValuePair) {
        let maxAtkDis = 1e5
        for (let key in this.sheets) {
            let sheet = this.sheets[key]
            if(sheet.area){
                maxAtkDis = sheet.area.transform[0] + sheet.area.transform[6] * 50
            }
            if(sheet.emit){
                maxAtkDis = Math.min(sheet.emit.lockDistance || 0, sheet.emit.translate.x * sheet.emit.duration)
            }
            if(maxAtkDis < this.attackStraightDistance){
                this.attackStraightDistance = maxAtkDis
                this.isAttackMotion = true
            }
        }
    }
}

class MotionTemplate{
    normal_atk:Motion = new Motion('normal_atk',15,false,1,0,{
        [0]:new MotionSheets(
            '29769', //动画ID
            15, //动画时长
            null, //特效ID
            null, //特效绑定槽位
            null, //特效Transform
            null, //特效颜色
            null, //投影特效
            null, //判定Transform
            null, //判定成功特效ID
            null, //判定特效缩放
            null, //判定特效颜色
            null, //判定成功音效ID
            null, //判定伤害系数
            null, //判定聚怪功能
            null, //判定击退力度
            null, //判定击飞力度
            null, //施加debuff
            null, //附加属性类型
            null, //附加属性值
            null, //音效ID
            null, //音量
            null, //位移
            null, //脱手特效ID
            null, //脱手技能持续帧数
            null, //脱手每帧位移
            null, //脱手技能初始位置偏移
            null, //脱手特效旋转
            null, //脱手特效缩放
            null, //脱手判定缩放
            null, //脱手命中特效
            null, //脱手命中特效缩放
            null, //脱手命中伤害系数
            null, //脱手命中后是否销毁
            null, //脱手重复命中间隔
            null, //法术场重力
            null, //法术场锁敌范围
            null, //法术场锁敌弹道类型
            null, //法术场锁敌弹道参数
            null, //法术场附加属性类型
            null, //法术场附加属性值
            null, //法术场颜色
            null, //浮空持续帧数
            null, //瞬闪判定范围
            null, //中断点
            null, //摄像机瞬时位移
            null, //摄像机瞬时旋转
            null, //摄像机平滑位移
            null, //摄像机平滑旋转
            null, //摄像机平滑位移持续时间
            null, //隐身持续时间
            null, //产生buffID
            null, //向周围派发buff影响类型
            null, //向周围派发buff产生buffID
            null, //向周围派发buff范围
            null, //反击持续帧数
            null, //反击附加速度
            null, //槽位变更(目标槽位)
            null, //反击附加特效
        ),
        [4]:new MotionSheets(
            null, //动画ID
            null, //动画时长
            '31259', //特效ID
            null, //特效绑定槽位
            [0,0,150,-15,180,-60,1.5,1.5,4], //特效Transform
            null, //特效颜色
            null, //投影特效
            [80,0,0,0,0,0,2.2,2.2,1.7], //判定Transform
            null, //判定成功特效ID
            null, //判定特效缩放
            null, //判定特效颜色
            '205469', //判定成功音效ID
            1, //判定伤害系数
            null, //判定聚怪功能
            null, //判定击退力度
            null, //判定击飞力度
            null, //施加debuff
            null, //附加属性类型
            null, //附加属性值
            null, //音效ID
            null, //音量
            null, //位移
            null, //脱手特效ID
            null, //脱手技能持续帧数
            null, //脱手每帧位移
            null, //脱手技能初始位置偏移
            null, //脱手特效旋转
            null, //脱手特效缩放
            null, //脱手判定缩放
            null, //脱手命中特效
            null, //脱手命中特效缩放
            null, //脱手命中伤害系数
            null, //脱手命中后是否销毁
            null, //脱手重复命中间隔
            null, //法术场重力
            null, //法术场锁敌范围
            null, //法术场锁敌弹道类型
            null, //法术场锁敌弹道参数
            null, //法术场附加属性类型
            null, //法术场附加属性值
            null, //法术场颜色
            null, //浮空持续帧数
            null, //瞬闪判定范围
            null, //中断点
            null, //摄像机瞬时位移
            null, //摄像机瞬时旋转
            null, //摄像机平滑位移
            null, //摄像机平滑旋转
            null, //摄像机平滑位移持续时间
            null, //隐身持续时间
            null, //产生buffID
            null, //向周围派发buff影响类型
            null, //向周围派发buff产生buffID
            null, //向周围派发buff范围
            null, //反击持续帧数
            null, //反击附加速度
            null, //槽位变更(目标槽位)
            null, //反击附加特效
        ),

    });

}
export const MotionLibrary = new MotionTemplate()
export type MotionID = keyof MotionTemplate